Hand Following example

In this notebook, you will use Pypot and an Inverse Kinematics toolbox to make Torso's hands follow each other.

Your Torso has two arms, and you can use simple methods to get and set the position of each hand.

The experiment

To be more precise, we will tell the right hand to keep a constant distance with the moving left hand, like on the picture above :

The left arm will be compliant, so you can move it and watch the right arm following it.

Setting up the robot

We begin by configuring the robot, to fit our needs for the experiment.

Begin with some useful imports :


In [2]:
import time
import numpy as np
from poppy.creatures import PoppyTorso

Then, create your Pypot robot :


In [ ]:
poppy = PoppyTorso()

Initialize your robot positions to 0 :


In [5]:
for m in poppy.motors:
    m.goto_position(0, 2)

The left arm must be compliant (so you can move it), and the right arm must be active


In [ ]:
# Left arm is compliant, right arm is active
for m in poppy.l_arm:
            m.compliant = False

for m in poppy.r_arm:
    m.compliant = False

# The torso itself must not be compliant
for m in poppy.torso:
    m.compliant = False

Following the left hand

To follow the left hand, the script will do the following steps :

  • Find the 3D position of the left hand, with Forward Kinematics
  • Assign this position ( + a gap to avoid collision) as the target of the right hand
  • Tell the right hand to reach this target

That's exactly what we do in the hand_follow function :


In [ ]:
def follow_hand(poppy, delta):
    """Tell the right hand to follow the left hand"""
    right_arm_position = poppy.l_arm_chain.end_effector + delta
    poppy.r_arm_chain.goto(right_arm_position, 0.5, wait=True)

Now, do this repeatedly in a loop :


In [ ]:
try:
    while True:
        follow_hand(poppy, target_delta)
        time.sleep(delay_time)

# Close properly the object when finished
except KeyboardInterrupt:
    poppy.close()

And you're done! Now you can move the left arm of the robot and see the right arm following.

About the libraries

  • The Inverse Kinematics functionnalities are provided by the IKPy library

  • The robot used here is part of the poppy-project, which also provides the motor-control library, Pypot.